/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.tnmk.worktime.gui;

import org.tnmk.worktime.service.action.ScheduledAction;

/**
 * Controllers are classes which handle GUI behaviors. Update ViewModel to GUI and vise versa.
 * @author Administrator
 */
public class WaterRemindController {
  private final MainFrame frame;
  private ScheduledAction waterAlert;

  public WaterRemindController(MainFrame frame) {
    this.frame = frame;
  }

  public void initAlertWaterScheduler() {
    String sPeriod = frame.jtxtWaterAlertPeriod.getText();
    Integer period = Integer.valueOf(sPeriod);
    waterAlert = new ScheduledAction(period) {
      public void run() {
        String countStr = frame.jtxtWater.getText();
        int count = Integer.valueOf(countStr);
        this.setCount(count);
        frame.alertMessage("Finish " + (count) + " bottle(s) yet?");
//        int result = JOptionPane.showConfirmDialog(frame, "Finish " + (count) + " bottle(s) yet?", "Water", JOptionPane.YES_NO_OPTION);
//        if (result == JOptionPane.OK_OPTION) {
//          this.inCreaseTime();
//          frame.jtxtWater.setText("" + this.getCount());
//        }
      }
    };
    waterAlert.start();
  }

  public void updateWaterAlertPeriod() {
    String sPeriod = frame.jtxtWaterAlertPeriod.getText();
    Integer period = Integer.valueOf(sPeriod);
    this.waterAlert.resetSchedule(period);//30 minuttes
  }

  public void updateWaterCount() {
    String countStr = frame.jtxtWater.getText();
    int count = Integer.valueOf(countStr);
    waterAlert.setCount(count);
  }

  public void increaseWaterCount() {
    String countStr = frame.jtxtWater.getText();
    int count = Integer.valueOf(countStr);
    waterAlert.setCount(count);
    count = waterAlert.inCreaseTime();
    frame.jtxtWater.setText("" + count);
  }
}
